/* Abstract Class ActionWidget
 * 
 * Extends PWF.ActionWidget with functionality to execute one action
 * 
 * This class uses the mixin AjaxRequest directly instead of the Action class.
 * This makes 
 * 
 * @author David Lindkvist (david.lindkvist@shapeshift.s
 */

PWF.create('PWF.SingleActionWidget', 
			PWF.ActionWidget, 
{			
	/***** PRIVATE METHODS ***********************************************************/
	onInternalInit: function() 
	{
		this.showLoadingAnimation();
	},
	
	onInternalSuccess: function(/*Object*/json) 
	{	
		this.hideLoadingAnimation();
		this.onActionSuccess(json);			
	},
	
	onInternalFailure: function(/*String*/errorMsg, json) 
	{
		this.hideLoadingAnimation();
		this.onActionFailure(errorMsg, json);
	},
	
	/***** PROTECTED METHODS *********************************************************/
	setActionName: function(/*String*/actionName) 
	{
		this.action = this.createAction(actionName, 
				  				 	 	this.onInternalInit, 
				  				 	 	this.onInternalSuccess, 
				  				 	 	this.onInternalFailure);
	},
	
	setActionUrl: function(/*String*/actionUrl) 
	{
		this.action = this.createActionByUrl(actionUrl, 
				  				 	 		 this.onInternalInit, 
				  				 	 		 this.onInternalSuccess, 
				  				 	 		 this.onInternalFailure);
	},
	
	clearActionParameters: function()
	{
		this.action.clearParameters();
	},
	
	addActionParameter: function(/*String*/key, /*String*/value)
	{
		this.action.addParameter(key, value);
	},
	
	runAction: function() 
	{
		this.action.run();
	},
	
	/***** ABSTRACT METHODS *********************************************************/
	onActionSuccess: function(/*Object*/json)
	{
		//override me pls!
	},
	
	onActionFailure: function(/*String*/errorMsg)
	{
		//override me pls!
	}
});